package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.common.Result;
import com.amsp.oa.oademo.entity.DengjiEmployeeAccess;
import com.amsp.oa.oademo.service.DengjiEmployeeAccessService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/dengji-employee-access")
@Api(tags = "员工临时出入登记接口")
public class DengjiEmployeeAccessController {

    @Autowired
    private DengjiEmployeeAccessService dengjiEmployeeAccessService;

    @PostMapping("/save")
    @ApiOperation("保存员工临时出入记录")
    public Result<Boolean> save(@RequestBody List<DengjiEmployeeAccess> records) {
        return Result.ok(dengjiEmployeeAccessService.saveOrUpdateBatch(records));
    }

    @GetMapping("/list")
    @ApiOperation("获取员工临时出入记录列表")
    public Result<IPage<DengjiEmployeeAccess>> list(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String employeeId,
            @RequestParam(required = false) String date) {
        return Result.ok(dengjiEmployeeAccessService.getPage(current, size, name, employeeId, date));
    }

    @GetMapping("/{id}")
    @ApiOperation("获取员工临时出入记录详情")
    public Result<DengjiEmployeeAccess> getById(@PathVariable Long id) {
        return Result.ok(dengjiEmployeeAccessService.getById(id));
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除员工临时出入记录")
    public Result<Boolean> delete(@PathVariable Long id) {
        return Result.ok(dengjiEmployeeAccessService.removeById(id));
    }
} 